<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>二分查找法</title>
	<script>
	var num=Number(prompt('请输入1-10直接的数字'));
	var arr=[1,2,3,4,5,6,7,8,9,10];
	var minIndex=0;
	var maxIndex=arr.length;
    var midIndex=(minIndex+maxIndex)/2
    console.log(midIndex);
    while(true){
    	if (num==arr[midIndex]) {
    		console.log('你所输入的数字的索引为'+midIndex);
    		break;
    	}else if (num>arr[midIndex]) {
    		minIndex=midIndex;
    		midIndex=parseInt((minIndex+maxIndex)/2);
    	}else{
    		maxIndex=midIndex;
    		midIndex=parseInt((minIndex+maxIndex)/2);
    	}
    }
	</script>
</head>
<body>
	
</body>
</html>